package com.bot.nft.module.mb.api;

import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.mb.domain.bo.MbKycBo;
import com.bot.nft.module.mb.domain.vo.MbKycVo;
import com.bot.nft.module.mb.service.IMbKycService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 描述:实名认证
 * 时间: 2024-01-14 21:30
 * 负责人: 卢梦丽
 **/
@CrossOrigin
@RestController
@RequestMapping("/app/mb")
public class KycController {

    /**
     * 实名认证接口
     */
    @Resource
    private IMbKycService iMbKycService;

    /**
     * 实名认证功能
     *
     * @param mbKycBo 认证信息
     * @return
     */
    @PostMapping("/kyc.do")
    public CommonResult<Boolean> kyc(@RequestBody MbKycBo mbKycBo) {
        String name = mbKycBo.getName();
        if (null == name || "" == name) {
            return CommonResult.error("姓名不能为空，请重新输入");
        }
        String idNo = mbKycBo.getIdNo();
        if (null == idNo || "" == idNo) {
            return CommonResult.error("身份证号不能为空，请重新输入");
        }
        Boolean kyc = iMbKycService.Kyc(name, idNo);

        if (!kyc) {
            return CommonResult.error("实名认证未通过，请重新认证");
        } else if (kyc) {
            //添加实名认证信息
            Boolean addKyc = iMbKycService.addKyc(mbKycBo);
            if (!addKyc) {
                return CommonResult.error("添加失败");
            }
            Boolean updateStatus = iMbKycService.updateStatus(mbKycBo.getMbId());
            if (!updateStatus) {
                return CommonResult.error();
            }
        }


        return CommonResult.ok();
    }

    /**
     * 查看实名认证信息
     *
     * @param mdId
     * @return memberMbInfo
     */
    @GetMapping("/{mdId}/getKyc.do")
    public CommonResult<MbKycVo> getKYCInfo(@PathVariable("mdId") String mdId) {
        MbKycVo mbKyc = iMbKycService.getMbKyc(mdId);
        return CommonResult.data(mbKyc);

    }

}
